#pragma once

#include "noncopyable.h"

#include <atomic>
#include <functional>
#include <memory.h>
#include <memory>
#include <string>
#include <thread>
#include <unistd.h>

class Thread : noncopyable {
  public:
    using ThreadFunc = std::function<void()>;

    explicit Thread(ThreadFunc, const std::string &name = std::string());
    ~Thread();

    void start();
    void join();

    bool started() const { return started_; }
    pid_t tid() const { return tid_; }
    const std::string &name() const { return name_; }

    static int num_created() { return num_created_; }

  private:
    void set_default_name();

    bool started_;
    bool joined_;
    std::shared_ptr<std::thread> thread_; // 这里不用thread 因为这个好像会直接开始生命周期
    pid_t tid_;
    ThreadFunc func_;
    std::string name_;
    static std::atomic_int num_created_;
};